﻿using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;

namespace UnityEngine.UI
{
	// Token: 0x02000038 RID: 56
	[AddComponentMenu("UI/BoxSlider", 35)]
	[RequireComponent(typeof(RectTransform))]
	public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement, IEventSystemHandler
	{
		// Token: 0x06000136 RID: 310 RVA: 0x0000D7E9 File Offset: 0x0000B9E9
		protected BoxSlider()
		{
		}

		// Token: 0x1700002A RID: 42
		// (get) Token: 0x06000137 RID: 311 RVA: 0x0000D828 File Offset: 0x0000BA28
		// (set) Token: 0x06000138 RID: 312 RVA: 0x0000D830 File Offset: 0x0000BA30
		public RectTransform handleRect
		{
			get
			{
				return this.m_HandleRect;
			}
			set
			{
				if (BoxSlider.SetClass<RectTransform>(ref this.m_HandleRect, value))
				{
					this.UpdateCachedReferences();
					this.UpdateVisuals();
				}
			}
		}

		// Token: 0x1700002B RID: 43
		// (get) Token: 0x06000139 RID: 313 RVA: 0x0000D84F File Offset: 0x0000BA4F
		// (set) Token: 0x0600013A RID: 314 RVA: 0x0000D857 File Offset: 0x0000BA57
		public float minValue
		{
			get
			{
				return this.m_MinValue;
			}
			set
			{
				if (BoxSlider.SetStruct<float>(ref this.m_MinValue, value))
				{
					this.Set(this.m_Value);
					this.SetY(this.m_ValueY);
					this.UpdateVisuals();
				}
			}
		}

		// Token: 0x1700002C RID: 44
		// (get) Token: 0x0600013B RID: 315 RVA: 0x0000D888 File Offset: 0x0000BA88
		// (set) Token: 0x0600013C RID: 316 RVA: 0x0000D890 File Offset: 0x0000BA90
		public float maxValue
		{
			get
			{
				return this.m_MaxValue;
			}
			set
			{
				if (BoxSlider.SetStruct<float>(ref this.m_MaxValue, value))
				{
					this.Set(this.m_Value);
					this.SetY(this.m_ValueY);
					this.UpdateVisuals();
				}
			}
		}

		// Token: 0x1700002D RID: 45
		// (get) Token: 0x0600013D RID: 317 RVA: 0x0000D8C1 File Offset: 0x0000BAC1
		// (set) Token: 0x0600013E RID: 318 RVA: 0x0000D8C9 File Offset: 0x0000BAC9
		public bool wholeNumbers
		{
			get
			{
				return this.m_WholeNumbers;
			}
			set
			{
				if (BoxSlider.SetStruct<bool>(ref this.m_WholeNumbers, value))
				{
					this.Set(this.m_Value);
					this.SetY(this.m_ValueY);
					this.UpdateVisuals();
				}
			}
		}

		// Token: 0x1700002E RID: 46
		// (get) Token: 0x0600013F RID: 319 RVA: 0x0000D8FA File Offset: 0x0000BAFA
		// (set) Token: 0x06000140 RID: 320 RVA: 0x0000D919 File Offset: 0x0000BB19
		public float value
		{
			get
			{
				if (this.wholeNumbers)
				{
					return Mathf.Round(this.m_Value);
				}
				return this.m_Value;
			}
			set
			{
				this.Set(value);
			}
		}

		// Token: 0x1700002F RID: 47
		// (get) Token: 0x06000141 RID: 321 RVA: 0x0000D922 File Offset: 0x0000BB22
		// (set) Token: 0x06000142 RID: 322 RVA: 0x0000D957 File Offset: 0x0000BB57
		public float normalizedValue
		{
			get
			{
				if (Mathf.Approximately(this.minValue, this.maxValue))
				{
					return 0f;
				}
				return Mathf.InverseLerp(this.minValue, this.maxValue, this.value);
			}
			set
			{
				this.value = Mathf.Lerp(this.minValue, this.maxValue, value);
			}
		}

		// Token: 0x17000030 RID: 48
		// (get) Token: 0x06000143 RID: 323 RVA: 0x0000D971 File Offset: 0x0000BB71
		// (set) Token: 0x06000144 RID: 324 RVA: 0x0000D990 File Offset: 0x0000BB90
		public float valueY
		{
			get
			{
				if (this.wholeNumbers)
				{
					return Mathf.Round(this.m_ValueY);
				}
				return this.m_ValueY;
			}
			set
			{
				this.SetY(value);
			}
		}

		// Token: 0x17000031 RID: 49
		// (get) Token: 0x06000145 RID: 325 RVA: 0x0000D999 File Offset: 0x0000BB99
		// (set) Token: 0x06000146 RID: 326 RVA: 0x0000D9CE File Offset: 0x0000BBCE
		public float normalizedValueY
		{
			get
			{
				if (Mathf.Approximately(this.minValue, this.maxValue))
				{
					return 0f;
				}
				return Mathf.InverseLerp(this.minValue, this.maxValue, this.valueY);
			}
			set
			{
				this.valueY = Mathf.Lerp(this.minValue, this.maxValue, value);
			}
		}

		// Token: 0x17000032 RID: 50
		// (get) Token: 0x06000147 RID: 327 RVA: 0x0000D9E8 File Offset: 0x0000BBE8
		// (set) Token: 0x06000148 RID: 328 RVA: 0x0000D9F0 File Offset: 0x0000BBF0
		public BoxSlider.BoxSliderEvent onValueChanged
		{
			get
			{
				return this.m_OnValueChanged;
			}
			set
			{
				this.m_OnValueChanged = value;
			}
		}

		// Token: 0x17000033 RID: 51
		// (get) Token: 0x06000149 RID: 329 RVA: 0x0000D9F9 File Offset: 0x0000BBF9
		private float stepSize
		{
			get
			{
				return (!this.wholeNumbers) ? ((this.maxValue - this.minValue) * 0.1f) : 1f;
			}
		}

		// Token: 0x0600014A RID: 330 RVA: 0x00002973 File Offset: 0x00000B73
		public virtual void Rebuild(CanvasUpdate executing)
		{
		}

		// Token: 0x0600014B RID: 331 RVA: 0x00002973 File Offset: 0x00000B73
		public void LayoutComplete()
		{
		}

		// Token: 0x0600014C RID: 332 RVA: 0x00002973 File Offset: 0x00000B73
		public void GraphicUpdateComplete()
		{
		}

		// Token: 0x0600014D RID: 333 RVA: 0x0000DA24 File Offset: 0x0000BC24
		public static bool SetClass<T>(ref T currentValue, T newValue) where T : class
		{
			if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
			{
				return false;
			}
			currentValue = newValue;
			return true;
		}

		// Token: 0x0600014E RID: 334 RVA: 0x0000DA7D File Offset: 0x0000BC7D
		public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
		{
			if (currentValue.Equals(newValue))
			{
				return false;
			}
			currentValue = newValue;
			return true;
		}

		// Token: 0x0600014F RID: 335 RVA: 0x0000DAA0 File Offset: 0x0000BCA0
		protected override void OnEnable()
		{
			base.OnEnable();
			this.UpdateCachedReferences();
			this.Set(this.m_Value, false);
			this.SetY(this.m_ValueY, false);
			this.UpdateVisuals();
		}

		// Token: 0x06000150 RID: 336 RVA: 0x0000DACE File Offset: 0x0000BCCE
		protected override void OnDisable()
		{
			this.m_Tracker.Clear();
			base.OnDisable();
		}

		// Token: 0x06000151 RID: 337 RVA: 0x0000DAE4 File Offset: 0x0000BCE4
		private void UpdateCachedReferences()
		{
			if (this.m_HandleRect)
			{
				this.m_HandleTransform = this.m_HandleRect.transform;
				if (this.m_HandleTransform.parent != null)
				{
					this.m_HandleContainerRect = this.m_HandleTransform.parent.GetComponent<RectTransform>();
				}
			}
			else
			{
				this.m_HandleContainerRect = null;
			}
		}

		// Token: 0x06000152 RID: 338 RVA: 0x0000DB4A File Offset: 0x0000BD4A
		private void Set(float input)
		{
			this.Set(input, true);
		}

		// Token: 0x06000153 RID: 339 RVA: 0x0000DB54 File Offset: 0x0000BD54
		private void Set(float input, bool sendCallback)
		{
			float num = Mathf.Clamp(input, this.minValue, this.maxValue);
			if (this.wholeNumbers)
			{
				num = Mathf.Round(num);
			}
			if (this.m_Value.Equals(num))
			{
				return;
			}
			this.m_Value = num;
			this.UpdateVisuals();
			if (sendCallback)
			{
				this.m_OnValueChanged.Invoke(num, this.valueY);
			}
		}

		// Token: 0x06000154 RID: 340 RVA: 0x0000DBBD File Offset: 0x0000BDBD
		private void SetY(float input)
		{
			this.SetY(input, true);
		}

		// Token: 0x06000155 RID: 341 RVA: 0x0000DBC8 File Offset: 0x0000BDC8
		private void SetY(float input, bool sendCallback)
		{
			float num = Mathf.Clamp(input, this.minValue, this.maxValue);
			if (this.wholeNumbers)
			{
				num = Mathf.Round(num);
			}
			if (this.m_ValueY.Equals(num))
			{
				return;
			}
			this.m_ValueY = num;
			this.UpdateVisuals();
			if (sendCallback)
			{
				this.m_OnValueChanged.Invoke(this.value, num);
			}
		}

		// Token: 0x06000156 RID: 342 RVA: 0x0000DC31 File Offset: 0x0000BE31
		protected override void OnRectTransformDimensionsChange()
		{
			base.OnRectTransformDimensionsChange();
			this.UpdateVisuals();
		}

		// Token: 0x06000157 RID: 343 RVA: 0x0000DC40 File Offset: 0x0000BE40
		private void UpdateVisuals()
		{
			this.m_Tracker.Clear();
			if (this.m_HandleContainerRect != null)
			{
				this.m_Tracker.Add(this, this.m_HandleRect, DrivenTransformProperties.Anchors);
				Vector2 zero = Vector2.zero;
				Vector2 one = Vector2.one;
				int index = 0;
				float value = this.normalizedValue;
				one[0] = value;
				zero[index] = value;
				int index2 = 1;
				value = this.normalizedValueY;
				one[1] = value;
				zero[index2] = value;
				this.m_HandleRect.anchorMin = zero;
				this.m_HandleRect.anchorMax = one;
			}
		}

		// Token: 0x06000158 RID: 344 RVA: 0x0000DCD8 File Offset: 0x0000BED8
		private void UpdateDrag(PointerEventData eventData, Camera cam)
		{
			RectTransform handleContainerRect = this.m_HandleContainerRect;
			if (handleContainerRect != null && handleContainerRect.rect.size[0] > 0f)
			{
				Vector2 a;
				if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(handleContainerRect, eventData.position, cam, out a))
				{
					return;
				}
				a -= handleContainerRect.rect.position;
				float normalizedValue = Mathf.Clamp01((a - this.m_Offset)[0] / handleContainerRect.rect.size[0]);
				this.normalizedValue = normalizedValue;
				float normalizedValueY = Mathf.Clamp01((a - this.m_Offset)[1] / handleContainerRect.rect.size[1]);
				this.normalizedValueY = normalizedValueY;
			}
		}

		// Token: 0x06000159 RID: 345 RVA: 0x0000DDC2 File Offset: 0x0000BFC2
		private bool MayDrag(PointerEventData eventData)
		{
			return this.IsActive() && this.IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
		}

		// Token: 0x0600015A RID: 346 RVA: 0x0000DDE8 File Offset: 0x0000BFE8
		public override void OnPointerDown(PointerEventData eventData)
		{
			if (!this.MayDrag(eventData))
			{
				return;
			}
			base.OnPointerDown(eventData);
			this.m_Offset = Vector2.zero;
			if (this.m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(this.m_HandleRect, eventData.position, eventData.enterEventCamera))
			{
				Vector2 offset;
				if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.m_HandleRect, eventData.position, eventData.pressEventCamera, out offset))
				{
					this.m_Offset = offset;
				}
				this.m_Offset.y = -this.m_Offset.y;
			}
			else
			{
				this.UpdateDrag(eventData, eventData.pressEventCamera);
			}
		}

		// Token: 0x0600015B RID: 347 RVA: 0x0000DE8F File Offset: 0x0000C08F
		public virtual void OnDrag(PointerEventData eventData)
		{
			if (!this.MayDrag(eventData))
			{
				return;
			}
			this.UpdateDrag(eventData, eventData.pressEventCamera);
		}

		// Token: 0x0600015C RID: 348 RVA: 0x0000DEAB File Offset: 0x0000C0AB
		public virtual void OnInitializePotentialDrag(PointerEventData eventData)
		{
			eventData.useDragThreshold = false;
		}

		// Token: 0x0600015D RID: 349 RVA: 0x0000DEB4 File Offset: 0x0000C0B4
		Transform ICanvasElement.get_transform()
		{
			return base.transform;
		}

		// Token: 0x0600015E RID: 350 RVA: 0x0000DEBC File Offset: 0x0000C0BC
		bool ICanvasElement.IsDestroyed()
		{
			return base.IsDestroyed();
		}

		// Token: 0x0400022F RID: 559
		[SerializeField]
		private RectTransform m_HandleRect;

		// Token: 0x04000230 RID: 560
		[SerializeField]
		[Space(6f)]
		private float m_MinValue;

		// Token: 0x04000231 RID: 561
		[SerializeField]
		private float m_MaxValue = 1f;

		// Token: 0x04000232 RID: 562
		[SerializeField]
		private bool m_WholeNumbers;

		// Token: 0x04000233 RID: 563
		[SerializeField]
		private float m_Value = 1f;

		// Token: 0x04000234 RID: 564
		[SerializeField]
		private float m_ValueY = 1f;

		// Token: 0x04000235 RID: 565
		[SerializeField]
		[Space(6f)]
		private BoxSlider.BoxSliderEvent m_OnValueChanged = new BoxSlider.BoxSliderEvent();

		// Token: 0x04000236 RID: 566
		private Transform m_HandleTransform;

		// Token: 0x04000237 RID: 567
		private RectTransform m_HandleContainerRect;

		// Token: 0x04000238 RID: 568
		private Vector2 m_Offset = Vector2.zero;

		// Token: 0x04000239 RID: 569
		private DrivenRectTransformTracker m_Tracker;

		// Token: 0x02000039 RID: 57
		public enum Direction
		{
			// Token: 0x0400023B RID: 571
			LeftToRight,
			// Token: 0x0400023C RID: 572
			RightToLeft,
			// Token: 0x0400023D RID: 573
			BottomToTop,
			// Token: 0x0400023E RID: 574
			TopToBottom
		}

		// Token: 0x0200003A RID: 58
		[Serializable]
		public class BoxSliderEvent : UnityEvent<float, float>
		{
		}

		// Token: 0x0200003B RID: 59
		private enum Axis
		{
			// Token: 0x04000240 RID: 576
			Horizontal,
			// Token: 0x04000241 RID: 577
			Vertical
		}
	}
}
